-
-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support the AUTO_RANDOM
Field
#104
Support the AUTO_RANDOM
Field
#104
Conversation
AUTO_RANDOM
Field
Change these two PR's implementation methods: For avoiding interface changes. |
PTAL @jinzhu |
mysql.go
Outdated
func autoRandomType(field *schema.Field) (bool, string) { | ||
if field.PrimaryKey && field.HasDefaultValue && | ||
strings.ToLower(strings.TrimSpace(field.DefaultValue)) == AutoRandomTag { | ||
field.HasDefaultValue = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to set HasDefaultValue
to false, it should be true?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We used this tag default:auto_random()
to implement the auto_random
feature. But it is actually not a default value. It's a field like auto_increment
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for auto_increment
fields we also marked them as HasDefaultValue
, e.g:
https://github.com/go-gorm/gorm/blob/d834dd60b715422dc2a900fb2744f9c278a9830f/schema/field.go#L113
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, got it. I made a mistake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. PTAL again.
What did this pull request do?
For this issue: go-gorm/gorm#5977
Support the
AUTO_RANDOM
.User Case Description
If you already deploy a TiDB at
localhost:4000
. You can use this code to test.